package com.ruoyi.prevention.segregater.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.people.student.domain.Student;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.prevention.segregater.domain.Segregater;
import com.ruoyi.prevention.segregater.service.ISegregaterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 隔离人员信息Controller
 * 
 * @author wad
 * @date 2022-04-06
 */
@RestController
@RequestMapping("/prevention/segregater")
public class SegregaterController extends BaseController
{
    @Autowired
    private ISegregaterService segregaterService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询隔离人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('prevention:segregater:list')")
    @GetMapping("/list")
    public TableDataInfo list(Segregater segregater)
    {
        startPage();
        List<Segregater> list = segregaterService.selectSegregaterList(segregater);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('prevention:segregater:list')")
    @GetMapping("/list2")
    public TableDataInfo list2(Segregater segregater)
    {
        startPage();
        List<Segregater> list = segregaterService.selectSegregaterList2(segregater);
        return getDataTable(list);
    }

    /**
     * 导出隔离人员信息列表
     */
    @PreAuthorize("@ss.hasPermi('prevention:segregater:export')")
    @Log(title = "隔离人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Segregater segregater)
    {
        List<Segregater> list = segregaterService.selectSegregaterList(segregater);
        ExcelUtil<Segregater> util = new ExcelUtil<Segregater>(Segregater.class);
        util.exportExcel(response, list, "隔离人员信息数据");
    }

    /**
     * 获取隔离人员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('prevention:segregater:query')")
    @GetMapping(value = "/{segreId}")
    public AjaxResult getInfo(@PathVariable("segreId") Long segreId)
    {
        return AjaxResult.success(segregaterService.selectSegregaterBySegreId(segreId));
    }

    /**
     * 新增隔离人员信息
     */
    @PreAuthorize("@ss.hasPermi('prevention:segregater:add')")
    @Log(title = "隔离人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Segregater segregater)
    {
        return toAjax(segregaterService.insertSegregater(segregater));
    }

    /**
     * 修改隔离人员信息
     */
    @PreAuthorize("@ss.hasPermi('prevention:segregater:edit')")
    @Log(title = "隔离人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Segregater segregater)
    {
        return toAjax(segregaterService.updateSegregater(segregater));
    }

    /**
     * 删除隔离人员信息
     */
    @PreAuthorize("@ss.hasPermi('prevention:segregater:remove')")
    @Log(title = "隔离人员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{segreIds}")
    public AjaxResult remove(@PathVariable Long[] segreIds)
    {
        return toAjax(segregaterService.deleteSegregaterBySegreIds(segreIds));
    }

    @Log(title = "隔离人员信息", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('prevention:segregater:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Segregater> util = new ExcelUtil<Segregater>(Segregater.class);
        List<Segregater> userList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = segregaterService.importUser(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response){
        ExcelUtil<Segregater> util = new ExcelUtil<Segregater>(Segregater.class);
        util.importTemplateExcel(response, "用户数据");
    }
}
